/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: Feature2Evaluate.java
 * Date: 17/11/2010
 */

package com.ingenius.sau.shared.model.core;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.FetchGroups;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * Class <strong>Feature2Evaluate</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@FetchGroups({
		@FetchGroup(name = "with_factor", members = { @Persistent(name = "factor2Evaluate") }),
		@FetchGroup(name = "with_indicators", members = { @Persistent(name = "indicators2Evaluate") }) })
public class Feature2Evaluate implements BaseBean {

	// DATA

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(nullValue = NullValue.NONE)
	private String name;

	@Persistent(nullValue = NullValue.NONE)
	private String description;

	@Persistent(nullValue = NullValue.NONE)
	private String aspects2Evaluate;

	@Persistent(nullValue = NullValue.NONE)
	private float weighing;

	@Persistent(nullValue = NullValue.NONE)
	private String justify;

	@Persistent
	private float grade;

	@Persistent
	private Factor2Evaluate factor2Evaluate;

	@Persistent(mappedBy = "feature2Evaluate")
	@Element(dependent = "true")
	private List<Indicator2Evaluate> indicators2Evaluate;

	// CONSTRUCTORS

	public Feature2Evaluate() {
	}

	public Feature2Evaluate(String id) {
		this.id = id;
	}

	// METHODS
	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getAspects2Evaluate() {
		return aspects2Evaluate;
	}

	public void setAspects2Evaluate(String aspects2Evaluate) {
		this.aspects2Evaluate = aspects2Evaluate;
	}

	public float getWeighing() {
		return weighing;
	}

	public void setWeighing(float weighing) {
		this.weighing = weighing;
	}

	public String getJustify() {
		return justify;
	}

	public void setJustify(String justify) {
		this.justify = justify;
	}

	public float getGrade() {
		return grade;
	}

	public void setGrade(float grade) {
		this.grade = grade;
	}

	public Factor2Evaluate getFactor2Evaluate() {
		return factor2Evaluate;
	}

	public void setFactor2Evaluate(Factor2Evaluate factor2Evaluate) {
		this.factor2Evaluate = factor2Evaluate;
	}

	public List<Indicator2Evaluate> getIndicators2Evaluate() {
		return (indicators2Evaluate == null) ? indicators2Evaluate = new ArrayList<Indicator2Evaluate>()
				: indicators2Evaluate;
	}

	public void setIndicators2Evaluate(
			List<Indicator2Evaluate> indicators2Evaluate) {

		this.indicators2Evaluate = indicators2Evaluate;
	}

	public void addIndicator2Evaluate(Indicator2Evaluate indicator2Evaluate) {
		getIndicators2Evaluate().add(indicator2Evaluate);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Feature2Evaluate) {
			return ((Feature2Evaluate) obj).getId().equals(id);
		}
		return false;
	}

	public Feature2Evaluate toDTO() {
		if (this != null) {
			this.setIndicators2Evaluate(null);
		}
		return this;
	}

}
